package com.xingyang.controller;


import com.xingyang.controller.request.AccountLoginRequest;
import com.xingyang.controller.request.AccountRegisterRequest;
import com.xingyang.enums.BizCodeEnum;
import com.xingyang.service.AccountService;
import com.xingyang.service.FileService;
import com.xingyang.utils.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 信仰
 * @since 2023-11-23
 */
@RestController
@RequestMapping("/api/account/v1")
public class AccountController {

    @Autowired
    private FileService fileService;

    @Autowired
    private AccountService accountService;


    @PostMapping("upload")
    public JsonData upLoadUserImg(@RequestPart("file")MultipartFile multipartFile){
        String result=fileService.uploadUserImg(multipartFile);

        return result!=null?JsonData.buildSuccess(result):JsonData.buildResult(BizCodeEnum.FILE_UPLOAD_USER_IMG_FAIL);
    }


    /*
    * 用户注册
    * */
    @PostMapping("register")
    public  JsonData register(@RequestBody AccountRegisterRequest registerRequest){
       JsonData jsonData= accountService.register(registerRequest);
       return  jsonData;

    }

    /**
     * 登录
     * @param loginRequest
     * @return
     */
    @PostMapping("login")
    public JsonData register(@RequestBody AccountLoginRequest loginRequest){

        JsonData jsonData = accountService.login(loginRequest);
        return jsonData;
    }


}

